package com.yuw.producerandconsumer;

public class ThreadProducer extends Thread {
    // 属性
    private MyStack stack;

    public ThreadProducer(MyStack stack) {
        this.stack = stack;
    }

    // 行为
    @Override
    public void run() {
        // 通过重写run方法达到多线程的业务逻辑处理的目的
        while (true) {
            System.out.println("生产者生产了一个产品，进行入栈操作");
            // 入栈
            stack.push(new Object());
            // 休眠1s
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
